﻿using System.IO;
using UnityEngine;

namespace BToolkit
{
    public class StreamingAssetsSync
    {

        /// <summary>
        /// 用同步方式读取Android原生工程的assets目录（即Unity的StreamingAssets目录）,文件带后缀名。
        /// </summary>
        public static byte[] GetBytes(string filePath)
        {
#if UNITY_EDITOR
            return File.ReadAllBytes(Application.streamingAssetsPath + "/" + filePath);
#elif UNITY_ANDROID
            return AndroidHelper.CallStaticFunction<byte[]>("cn.helper.StreamingAssetsSync", "getBytes", filePath);
#elif UNITY_IOS
            return null;
#else
            return null;
#endif
        }

        /// <summary>
        /// 判断文件是否存在
        /// </summary>
        public static bool IsFileExist(string filePath)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            return AndroidHelper.CallStaticFunction<bool>("cn.helper.StreamingAssetsSync", "isFileExist", filePath);
#else
            return false;
#endif
        }
    }
}